package cn.edu.xhu.library_management.area.mapper;

import cn.edu.xhu.library_management.area.entity.LmArea;
import cn.edu.xhu.library_management.area.entity.LmBookRack;
import cn.edu.xhu.library_management.area.entity.LmBookRackArea;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * @Author: MMJ
 * @Date: 2022 - 09 - 30
 * @Description: 书架区域mapper
 */
public interface BookRackAreaMapper {
    /**
     * 通过组合式id，查询书架区域，包含(书架区域id，区域所在行，区域id(区域名称))
     *
     * @param area 组合对象
     * @return 书架区域对象
     */
    @Select("select *from lm_bookrack_area " +
            "where br_id = #{bookRackId} and ba_index_row=#{indexRow} and " +
            "ba_area_Id = #{bookAreaId}")
    @Results(id = "baseBookRackArea", value = {
            @Result(id = true, column = "ba_id", property = "id"),
            @Result(column = "ba_area_Id", property = "bookAreaId"),
            @Result(column = "ba_index_row", property = "indexRow"),
            @Result(column = "ba_area_number", property = "areaNumber"),
            @Result(column = "br_id", property = "bookRackId")
    })
    public LmBookRackArea findRackAreaByComposeId(LmBookRackArea area);

    /**
     * 通过书架区域id，查询书架区域
     *
     * @param areaId 书架区域id
     * @return 书架区域对象
     */
    @Select("select *from lm_bookrack_area where ba_id = #{areaId}")
    @ResultMap("baseBookRackArea")
    public LmBookRackArea findRackAreaById(Integer areaId);

    /**
     * 通过书架id和所在行，查询行所有区域
     * @param brId 书架id
     * @param indexRow 所以在行
     * @return 书架区域集合
     */
    @Select("select *from lm_bookrack_area where br_id=#{brId} and ba_index_row = #{indexRow}")
    @ResultMap("baseBookRackArea")
    public List<LmBookRackArea> findRackAreasByBrIDAndIndexRow(@Param("brId") Integer brId,@Param("indexRow") Integer indexRow);

    /**
     * 通过书架id，查询所有的书架区域
     * @param rackId 书架id
     * @return 书架区域集合
     */
    @Select("select *from lm_bookrack_area where br_id = #{rackId}")
    @ResultMap("baseBookRackArea")
    public List<LmBookRackArea> findRackAreasByRackId(@Param("rackId") Integer rackId);

    /**
     * 添加书架区域
     *
     * @param rackArea 书架区域对象
     * @return 返回受影响的行数
     */
    @Insert("insert into lm_bookrack_area(ba_area_Id,ba_index_row,ba_area_number,br_id)" +
            "values (#{bookAreaId},#{indexRow},#{areaNumber},#{bookRackId})")
    public int addRackArea(LmBookRackArea rackArea);

    /**
     * 通过书架区域ID，修改书架区域
     *
     * @param rackArea 书架区域对象
     * @return 返回受影响的行数
     */
    public int updateRackArea(LmBookRackArea rackArea);

    /**
     * 通过书架区域ID，删除书架区域
     *
     * @param rackAreaId 书架区域ID
     * @return 受影响行数
     */
    @Delete("delete from lm_bookrack_area where ba_id = #{rackAreaId}")
    public int deleteRackAreaById(Integer rackAreaId);
}
